<?php
/**
 * Created by PhpStorm.
 * User: 12133
 * Date: 2024/4/2
 * Time: 14:17
 */

namespace app\model;


use think\Model;

class Quotation extends Model
{
    protected $pk = 'id';
    protected $table = 'quotation_all';
    protected $autoWriteTimestamp = 'datetime';
    public $is_new = false;
    public function getIsTaxAttr($value){
        if ($value == 1)return'是';
        else return '否';
    }
    public function is_new($is_new = false){
        $this->is_new = $is_new;
        if ($is_new == true){
            $this->pk = 'uniqid';
            $this->table = 'quotation_new';
            $this->autoWriteTimestamp = NULL;
        }else{
            $this->pk = 'id';
            $this->table = 'quotation_all';
            $this->autoWriteTimestamp = 'datetime';
        }
        return $this;
    }


    public function all_install($install) : void{
        $supplier = array_column($install,'supplier');
        $this->is_new(true)->where('supplier','IN',$supplier)->delete();
        $this->is_new(false)->saveAll($install);
        $field = ['update_time'];
        foreach ($install AS $key => $value) {
            foreach ($field AS $index => $item) unset($value[$item]);
            $value['uniqid'] = md5(uniqid().rand(100,999).time().rand(1,999999999).'3324');
            $value['create_time'] = date('Y-m-d H:i:s');
            $message[] = $value;
        }
        $this->is_new(true)->insertAll($message);
    }

}